package cn.com.algery.temp.service.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.com.algery.temp.dao.UserMapper;
import cn.com.algery.temp.domain.Page;
import cn.com.algery.temp.domain.Roles;
import cn.com.algery.temp.domain.User;
import cn.com.algery.temp.domain.UserRoles;
import cn.com.algery.temp.service.UserService;

@Service
public class UserServiceImpl implements UserService {
	@Resource
	private UserMapper userMapper;

	@Override
	public User queryUserByName(String username) {
		// TODO Auto-generated method stub
		
		return userMapper.queryUserByName(username);
	}

	@Override
	public Set<String> queryRolesByName(String userName) {
		// TODO Auto-generated method stub
		return userMapper.queryRolesByName(userName);
	}

	@Override
	public Map<String, Object> queryAllUserRoles(Page page) {
		String userName = page.getFilterItem();
		Integer limit = page.getLimit();
		Integer startNum = ( page.getPage() - 1 ) * limit;
		Map<String, Object> map = new HashMap<>();
		List<UserRoles> dataList = userMapper.queryAllUserRoles(startNum,limit,userName);
		Integer count = userMapper.getUserRolesCount(userName);
		map.put("total", count);
		map.put("dataList", dataList);
		return map;
	}

	@Override
	public void saveUserRole(UserRoles userRoles) {
		userMapper.updateUserRoles(userRoles);
	}

	@Override
	public List<Roles> queryAllRoles() {
		return userMapper.queryAllRoles();
	}

	@Override
	public void updateUser(User user) {
		userMapper.updateUser(user);;
	}

}
